"Polyglot" Language Switcher jQuery Plugin Documentation by Ixtendo, v1.3
Website: www.ixtendo.com · Email: info@ixtendo.com
The "Polyglot" Language Switcher jQuery plugin allows you easily switch between the languages supported by your website. It was conceived as a drop-down menu with flag icons.
All the callback functions have a single parameter which is a simple object with the following properties:
The above parameters can be specified to the library as follows:
…
$(this).polyglotLanguageSwitcher({paramName:'language'}); //chaging the language parameter name
$(this).polyglotLanguageSwitcher({effect:'slide'}); //chaging the open/close popup effect
$(this).polyglotLanguageSwitcher({ //example of multiple configuration paremeters
paramName: 'language',
effect: 'slide',
animSpeed: 150
});
//example of onChange callback function
$(this).polyglotLanguageSwitcher({
onChange: function(evt){
alert("The selected language is: "+evt.selectedItem);
return true;
}
});
/* Example of popup closure on a mobile device (e.g., IPad, IPhone, etc.) when the user presses outside it.
To implement this, you need to integrate the jQuery touchSwipe library in your website. This library can be found at
the following address: https://github.com/mattbryson/TouchSwipe-Jquery-Plugin. */
$(this).polyglotLanguageSwitcher({
afterLoad: function(evt){
$(document).swipe( {
click:function(e, target){
evt.instance.close();
}
});
}
});
…
To use the "Polyglot" Language Switcher in you website, add the following lines of code in the <head> tag of your web page:
<head>
…
<link href="css/polyglot-language-switcher.css" type="text/css" rel="stylesheet">
<script src="js/jquery-1.7.min.js" type="text/javascript"></script>
<script src="js/jquery.polyglot.language.switcher-1.3.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$(this).polyglotLanguageSwitcher();
});
</script>
</head>
In the <body> section of your page, add the following lines of code:
<body> … <div id="polyglotLanguageSwitcher"> <form action="#"> <select id="polyglot-language-options"> <option id="en" value="en">English</option> <option id="fr" value="fr" selected>French</option> <option id="de" value="de">German</option> <option id="it" value="it">Italian</option> <option id="es" value="es">Spanish</option> </select> </form> </div> … </body>
When the ‘websiteType’ configuration parameter has the value of ‘dynamic’, after the user changes the language, the newly generated pages must select the option which corresponds to the selected language. For example, if the Italian language was selected, then all the pages generated by the server must select the option with an id of ‘it’.
In the case of static websites (where the pages are pure HTML and aren't generated by a programming language), the selected attribute of the option element will not be taken into account. In this case, the selected value will be stored in the local cache (using HTML5 local storage). It is possible that this case will not work properly on some older browsers which don't support HTML5 local storage.